package com.triones.api.controller.api.interlace;

import cn.dev33.satoken.annotation.SaIgnore;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.triones.api.entity.bo.EmailChangeRecordBO;
import com.triones.api.entity.bo.UpdatePwdBO;
import com.triones.api.entity.interlace.dto.InterlaceBlockchainAddressCatalogueDO;
import com.triones.api.entity.interlace.vo.InterlaceBlockchainAddressCatalogueVO;
import com.triones.api.entity.vo.CustomInviteRecordVO;
import com.triones.api.service.interlace.InterlaceMemberService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * api - interlace 用户会员相关接口
 *
 * @Author: triones
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/api/interlace/member")
public class ApiInterlaceMemberController extends BaseController {

    private final InterlaceMemberService interlaceMemberService;

    /**
     * 检查是否具备白标用户申请条件
     * true:具备、false:不具备
     */
    @GetMapping("/checkHaveApplyVip")
    public R<Boolean> checkHaveApplyVip() {
        return R.ok("操作成功！",interlaceMemberService.checkHaveApplyVip());
    }

    /**
     * 白标用户申请
     */
    @RepeatSubmit
    @PostMapping("/applyVip")
    public R<Void> applyVip() {
        return toAjax(interlaceMemberService.apiApplyVip());
    }

    /**
     * 个人中心 -常用地址列表（分页）
     */
    @GetMapping("/crypto/blockchainAddressCatalogue")
    public TableDataInfo<InterlaceBlockchainAddressCatalogueVO> blockchainAddressCataloguePageList(String keyword,PageQuery pageQuery) {
        return interlaceMemberService.blockchainAddressCataloguePageList(keyword,pageQuery);
    }

    /**
     * 个人中心 -常用地址新增
     */
    @RepeatSubmit
    @PostMapping("/crypto/blockchainAddressCatalogue")
    public R<Void> addBlockchainAddressCatalogue(@Validated @RequestBody InterlaceBlockchainAddressCatalogueDO dto) {
        if (!interlaceMemberService.checkNickNameUnique(dto)) {
            return R.fail("新增常用地址失败，昵称已存在！");
        }
        return toAjax(interlaceMemberService.addBlockchainAddressCatalogue(dto));
    }

    /**
     * 个人中心 -常用地址详情
     */
    @GetMapping("/crypto/blockchainAddressCatalogue/{id}")
    public R<InterlaceBlockchainAddressCatalogueVO> blockchainAddressCatalogueDetail(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        return R.ok(interlaceMemberService.blockchainAddressCatalogueDetail(id));
    }

    /**
     * 个人中心 -常用地址修改
     */
    @RepeatSubmit
    @PutMapping("/crypto/blockchainAddressCatalogue")
    public R<Void> editBlockchainAddressCatalogue(@Validated @RequestBody InterlaceBlockchainAddressCatalogueDO dto) {
        if (!interlaceMemberService.checkNickNameUnique(dto)) {
            return R.fail("修改常用地址失败，昵称已存在！");
        }
        return toAjax(interlaceMemberService.editBlockchainAddressCatalogue(dto));
    }

    /**
     * 个人中心 -常用地址删除
     */
    @RepeatSubmit
    @DeleteMapping("/crypto/blockchainAddressCatalogue/{id}")
    public R<Void> removeBlockchainAddressCatalogue(@NotNull(message = "主键不能为空") @PathVariable("id") Long id) {
        return toAjax(interlaceMemberService.removeBlockchainAddressCatalogue(id));
    }

    /**
     * 推广中心 -用户列表（分页）
     */
    @GetMapping("/invite/memberPageList")
    public TableDataInfo<CustomInviteRecordVO> apiInviteMemberPageList(String isEffective, PageQuery pageQuery) {
        return interlaceMemberService.apiInviteMemberPageList(isEffective,pageQuery);
    }

    /**
     * 个人中心 -修改登录密码
     */
    @SaIgnore
    @PutMapping("/updatePwd")
    public R<Void> updatePwd(@Validated @RequestBody UpdatePwdBO bo) {
        return toAjax(interlaceMemberService.updatePwd(bo));
    }

    /**
     * 更换邮箱
     */
    @RepeatSubmit
    @PostMapping("/emailRedirect")
    public R<Void> emailRedirect(@RequestBody EmailChangeRecordBO bo) {
        return toAjax(interlaceMemberService.emailRedirect(bo));
    }
}
